package com.banyuan.servlet.opus;

import com.banyuan.dao.TypesDao;
import com.banyuan.domain.Types;
import com.banyuan.utils.DBUtils;
import com.banyuan.utils.JDBCUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

@WebServlet("/opus/addPage")
public class AddPageServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ResultSet resultSet = null;
        try {
            resultSet = TypesDao.selectAll("", "");
            List<Types> typesList = DBUtils.resultToBeanAll(resultSet, Types.class);
            req.setAttribute("typesList",typesList);
            System.out.println(typesList);
            req.getRequestDispatcher("/WEB-INF/pages/opus/add.jsp").forward(req,resp);


        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            JDBCUtils.closeBy(resultSet);
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
